let initStates = {
  name: '首页导航',
  listData: [],
  wave: [],
  loading: false
}

const namespace = 'demo1'

function initType(type) {
  if (typeof type === 'string' && type !== '') {
    const tmpTypeText = type.split(namespace + '/')
    if (tmpTypeText.length === 2) {
      return tmpTypeText[1]
    } else {
      return ''
    }
  } else {
    return ''
  }
}

export default function (state = initStates, action) {
  const type = initType(action.type)
  switch (type) {
    case 'ADD_LIST':
      console.log('state.listData', state.listData)
      return Object.assign({}, state, {
        listData: [...state.listData, action.data],
        loading: false
      })
    case 'GET_LIST_LOADING':
      console.log('action.data', action.data)
      return Object.assign({}, state, {
        loading: action.data
      })
    case 'GET_LIST':
      return Object.assign({}, state, {
        listData: action.data,
        loading: false
      })
    case 'HOME_INIT':
      return Object.assign({}, state, {
        listData: action.data
      })

    case 'WAVE_DATA':
      return Object.assign({}, state, {
        wave: [
          ...action.data
        ]
      })
    default:
      return state
  }
}
